layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 同城搬家车类型管理
     */
    var FlowServiceType = {
        tableId: "flowServiceTypeTable"
    };

    /**
     * 初始化表格的列
     */
    FlowServiceType.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'serviceTypeId', hide: true, title: 'ID'},
            {field: 'typeName', sort: true, title: '车辆类型'},
            {field: 'typeUrl', sort: true, title: '车辆图片',templet:function (row) {
                    return row.typeUrl ? "<img src='"+row.typeUrl+"' />" : "无";
            }},
            {field: 'type', sort: true, title: '类型',templet:function (row) {
                    return row.type == 0 ? '全包' : '计算物品费';
            }},
            {field: 'carPrice', sort: true, title: '车辆费用'},
            {field: 'createTime', sort: true, title: '创建时间'},
            {field: 'memberNumber', sort: true, title: '搬运人数'},
            {align: 'center', toolbar: '#tableBar', title: '操作',width:250}
        ]];
    };

    /**
     * 点击查询按钮
     */
    FlowServiceType.search = function () {
        var queryData = {};


        table.reload(FlowServiceType.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

     /**
      * 点击编辑
      *
      * @param data 点击按钮时候的行数据
      */
      FlowServiceType.openEditDlg = function (data) {
          func.open({
              title: '汽车公里费用配置',
              content: Feng.ctxPath + '/flowServiceDistancePrice?serviceTypeId=' + data.serviceTypeId+"&storeCityId="+Feng.getUrlParam("storeCityId"),
              tableId: FlowServiceType.tableId
          });
      };


    FlowServiceType.openAreaDlg = function (data) {
        func.open({
            title: '区间费用配置',
            content: Feng.ctxPath + '/flowServiceAreaPrice?serviceTypeId=' + data.serviceTypeId+"&storeCityId="+Feng.getUrlParam("storeCityId"),
            tableId: FlowServiceType.tableId
        });
    };

    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    FlowServiceType.openCarEditDlg = function (data) {
        func.open({
            title: '汽车费用配置',
            content: Feng.ctxPath + '/flowStoreCity/flowServiceTypePriceEdit?serviceTypeId=' + data.serviceTypeId+"&storeCityId="+Feng.getUrlParam("storeCityId"),
            tableId: FlowServiceType.tableId
        });
    };

    FlowServiceType.openElevatorDlg = function(data){
        func.open({
            title: '楼层计费配置',
            content: Feng.ctxPath + '/flowStoreCity/flowElevatorPrice?storeCityId=' + Feng.getUrlParam("storeCityId")+'&serviceTypeId='+data.serviceTypeId,
            tableId: FlowServiceType.tableId
        });
    };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + FlowServiceType.tableId,
        url: Feng.ctxPath + '/flowStoreCity/flowServiceTypeList?storeCityId='+Feng.getUrlParam("storeCityId"),
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: FlowServiceType.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        FlowServiceType.search();
    });

    // 工具条点击事件
    table.on('tool(' + FlowServiceType.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            FlowServiceType.openEditDlg(data);
        }else if(layEvent === 'editPrice'){
            FlowServiceType.openCarEditDlg(data);
        } else if (layEvent === 'elevatorConfig') {
            FlowServiceType.openElevatorDlg(data);
        }else if (layEvent === 'area') {
            FlowServiceType.openAreaDlg(data);
        }
    });
});
